package t_747

import "sort"

func dominantIndex(nums []int) int {
	le := len(nums)
	if le < 2 {
		if le == 1 {
			return 0
		}
		return -1
	}
	sli := make([]int, le)
	copy(sli, nums)
	sort.Ints(sli)
	max := sli[le-1]
	sec := sli[le-2]
	if max < sec*2 {
		return -1
	}

	m := make(map[int]int)

	for index, val := range nums {
		m[val] = index
	}

	return m[max]
}
